<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Weixin\Controller;
use User\Api\UserApi;

/**
 * 用户控制器
 * 包括用户中心，用户登录及注册
 */
class WxpayController extends WeixinController {

    public function wx_pay(){
    	if(IS_POST){
    		$uid=I('post.uid');
    		$shop_name=I('post.shop_name');
    		$money=I('post.money');
    		$danhao='wx'.date("YmdHis").rand(1000,9999);
    		$data=array(
				'uid'         =>$uid,
				'pay_money'   =>$money,
				'pay_time'    =>time(),
				'danhao'      =>$danhao,
			 	);
    		$id=D('Wxpay')->add($data);
    		if($id>0){
    			$url="http://pangguokangjcsmkj.cn/WxpayAPI2/example/jsapi.php?uid=".$uid."&money=".$money.'&id='.$id.'&shop_name='.$shop_name.'&danhao='.$danhao;;
    			echo "<script>location.href='{$url}'</script>";die;
    		
    		}

			// ini_set('date.timezone','Asia/Shanghai');
			// require_once (__ROOT__."WxpayAPI/lib/WxPay.Api.php");
			// require_once (__ROOT__."WxpayAPI/example/WxPay.JsApiPay.php");
			// //①、获取用户openid
			// $tools = new \JsApiPay;
			// $openId = $tools->GetOpenid();

			// //②、统一下单
			// $input = new \WxPayUnifiedOrder;
			// $danhao='wx'.date("YmdHis").rand(1000,9999);
			// $input->SetBody("到店付".$danhao);//商品描述----到店付+订单号

			// $input->SetOut_trade_no($danhao);//danhao
			// $money1=100*$money;
			// $input->SetTotal_fee($money1);//money
			// $input->SetTime_start(date("YmdHis"));
			// $input->SetTime_expire(date("YmdHis", time() + 600)); //10分钟内有效
			
			// $input->SetNotify_url("http://pangguokangjcsmkj.cn/wxpay.php");
			// $input->SetTrade_type("JSAPI");
			// $input->SetOpenid($openId);

			
			
			// ﻿﻿﻿ WxPayUnifiedOrder Object ( [values:protected] => Array ( [body] => 到店付wx201803261039393037 [out_trade_no] => wx201803261039393037 [total_fee] => 0 [time_start] => 20180326103939 [time_expire] => 20180326104939 [notify_url] => http://pangguokangjcsmkj.cn/wxpay.php [trade_type] => JSAPI [openid] => oQSHC1IAxo46w2s62JXbRhs7vhQE [appid] => wx836fd053646ff98a [mch_id] => 1500609701 [spbill_create_ip] => 116.211.165.1 [nonce_str] => 3fxq2sa646bf0s72tt499xfatnsh88c7 ) )

			// {"appId":"wx836fd053646ff98a","nonceStr":"k8bje5emvdvhte3p42bt36fml42p5udl","package":"prepay_id=wx20180326141935c938f4442b0808991927","signType":"MD5","timeStamp":"1522045175","paySign":"A58F8D65B6A5B658BBF42455C49AB47B"}
			
			// $WxPayApi=new \WxPayApi;
			// $order =$WxPayApi->unifiedOrder($input);

			// $jsApiParameters = $tools->GetJsApiParameters($order);


			// $api=json_decode($jsApiParameters,true);

			// $nonceStr=$api['nonceStr'];
			// $prepay_id=$order['prepay_id'];

			// $data=array(
			// 	'uid'         =>$uid,
			// 	'pay_money'   =>$money,
			// 	'pay_time'    =>time(),
			// 	'danhao'      =>$danhao,
			// 	'prepay_id'   =>$prepay_id,
			// 	'nonceStr'    =>$nonceStr,
			// 	'openid'      =>$openId,
			//  	);

			// $id=D('Wxpay')->add($data);


			// if($id>0){
			// 	$url="http://pangguokangjcsmkj.cn/WxpayAPI/example/jsapi.php?jsApiParameters={}";
			// 	echo "<script>location.href='{$url}'</script>";die;

			// }
    	}else{


    		$uid=$_GET['uid'];
    		$one=D('Ykyh')->where(['uid'=>$uid])->find();
    		$this->assign('one',$one);
            C('WEB_SITE_TITLE',$one['shop_name']);
            $this->display();
    	}
        

        

            
    }









      
  
}
